package dao;

import pojo.ClassicFormula;
import pojo.ClassicFormulaComposition;
import util.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class ClassicFormulaCompositionDao {
    private Connection conn = null;
    private PreparedStatement pstm = null;
    private ResultSet rs = null;

    public List<ClassicFormulaComposition> getCFCListByCFId(int cfid){
        List<ClassicFormulaComposition> cFCList = new ArrayList<>();
        try{

            conn  = DbUtil.getConnection();
            String sql = "select * from classicformulacomposition where cfid="+cfid;
            pstm = conn.prepareStatement(sql);
            rs = pstm.executeQuery(sql);
            while(rs.next()){
                ClassicFormulaComposition cf=new ClassicFormulaComposition();
                cf.setId(rs.getInt("id"));
                cf.setCfid(rs.getInt("cfid"));
                cf.setTcmid(rs.getInt("tcmid"));
                cf.setDosage(rs.getString("dosage"));
                cf.setUsage(rs.getString("usage"));
                cFCList.add(cf);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            DbUtil.close(conn, pstm, rs);
        }
        return cFCList;
    }
}
